package com.lc.stock.module.crawldata;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @author lichen
 * @description
 * @menu
 * @date 2023/2/7 9:21
 */
@Slf4j
@Service
public class CrawDataProcessService {

    @Autowired
    private ApplicationContext applicationContext;

    /**
     * 执行数据爬取
     * @param stockCodeList
     */
    public void crawDataByStockCode(List<String> stockCodeList){
        //获取抓取数据的业务层
        Map<String, ICrawData> crawDataMap = applicationContext.getBeansOfType(ICrawData.class);
        Collection<ICrawData> crawDataServiceColl = crawDataMap.values();

        for (String stockCode : stockCodeList) {
            crawDataServiceColl.forEach(item-> item.craw(stockCode));
        }
    }

}
